package com.yuelife.service.controller;

import com.github.pagehelper.PageInfo;
import com.yuelife.service.pojo.SCategory;
import com.yuelife.service.service.SCategoryService;
import entity.Result;
import entity.StatusCode;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/****
 * @Author:admin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/
@Api(value = "SCategoryController")
@RestController
@RequestMapping("/sCategory")
@CrossOrigin
public class SCategoryController {

    @Autowired
    private SCategoryService sCategoryService;

    /***
     * SCategory分页条件搜索实现
     * @param sCategory
     * @param page
     * @param size
     * @return
     */
    @ApiOperation(value = "SCategory条件分页查询",notes = "分页条件查询SCategory方法详情",tags = {"SCategoryController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false) @ApiParam(name = "SCategory对象",value = "传入JSON数据",required = false) SCategory sCategory, @PathVariable  int page, @PathVariable  int size){
        //调用SCategoryService实现分页条件查询SCategory
        PageInfo<SCategory> pageInfo = sCategoryService.findPage(sCategory, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * SCategory分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @ApiOperation(value = "SCategory分页查询",notes = "分页查询SCategory方法详情",tags = {"SCategoryController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用SCategoryService实现分页查询SCategory
        PageInfo<SCategory> pageInfo = sCategoryService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param sCategory
     * @return
     */
    @ApiOperation(value = "SCategory条件查询",notes = "条件查询SCategory方法详情",tags = {"SCategoryController"})
    @PostMapping(value = "/search" )
    public Result<List<SCategory>> findList(@RequestBody(required = false) @ApiParam(name = "SCategory对象",value = "传入JSON数据",required = false) SCategory sCategory){
        //调用SCategoryService实现条件查询SCategory
        List<SCategory> list = sCategoryService.findList(sCategory);
        return new Result<List<SCategory>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @ApiOperation(value = "SCategory根据ID删除",notes = "根据ID删除SCategory方法详情",tags = {"SCategoryController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Integer id){
        //调用SCategoryService实现根据主键删除
        sCategoryService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改SCategory数据
     * @param sCategory
     * @param id
     * @return
     */
    @ApiOperation(value = "SCategory根据ID修改",notes = "根据ID修改SCategory方法详情",tags = {"SCategoryController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @PutMapping(value="/{id}")
    public Result update(@RequestBody @ApiParam(name = "SCategory对象",value = "传入JSON数据",required = false) SCategory sCategory,@PathVariable Integer id){
        //设置主键值
        sCategory.setCategoryId(id);
        //调用SCategoryService实现修改SCategory
        sCategoryService.update(sCategory);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增SCategory数据
     * @param sCategory
     * @return
     */
    @ApiOperation(value = "SCategory添加",notes = "添加SCategory方法详情",tags = {"SCategoryController"})
    @PostMapping
    public Result add(@RequestBody  @ApiParam(name = "SCategory对象",value = "传入JSON数据",required = true) SCategory sCategory){
        //调用SCategoryService实现添加SCategory
        sCategoryService.add(sCategory);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询SCategory数据
     * @param id
     * @return
     */
    @ApiOperation(value = "SCategory根据ID查询",notes = "根据ID查询SCategory方法详情",tags = {"SCategoryController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @GetMapping("/{id}")
    public Result<SCategory> findById(@PathVariable Integer id){
        //调用SCategoryService实现根据主键查询SCategory
        SCategory sCategory = sCategoryService.findById(id);
        return new Result<SCategory>(true,StatusCode.OK,"查询成功",sCategory);
    }

    /***
     * 查询SCategory全部数据
     * @return
     */
    @ApiOperation(value = "查询所有SCategory",notes = "查询所SCategory有方法详情",tags = {"SCategoryController"})
    @GetMapping
    public Result<List<SCategory>> findAll(){
        //调用SCategoryService实现查询所有SCategory
        List<SCategory> list = sCategoryService.findAll();
        return new Result<List<SCategory>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
